package AcWing.每日一题2025;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author ZhuYi
 * @create 2025/3/11 16:34
 */
public class 哞叫时间2_6134 {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        int[] left = new int[n];
        int[] right = new int[n];
        String[] strs = br.readLine().split(" ");
        for (int i = 0; i < strs.length; i++) {
            arr[i] = Integer.parseInt(strs[i]);
        }

        Long res = 0L;
        int cnt = 0;//不同数的个数
        //从左到右统计每种数的个数
        for (int i = 0; i < n; i++) {
            int x = arr[i];
            if (++left[x] == 1) cnt++;
        }
        //从右到左，left--，right++,当后两位找到后和不同的数的个数相加，并去除全一样的情况
        for (int i = n - 1; i > 0; i--) {
            int x = arr[i];
            if (--left[x] == 0) cnt--;
            if (++right[x] == 2) {
                res += cnt;
                //去除全一样的情况
                if (left[x] > 0) {
                    res--;
                }
            }
        }
        System.out.println(res);

    }
}
